package com.cy1;

import java.util.*;

/**
 * @author CY
 * @date 2022/08/17 00:02
 **/
public class CollectionsDemo {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<String>();
        c.add("chenyong");
        c.add(new String("yuanxiang"));
        c.add(new String(new char[]{'s', 'h', 'i'}));
        System.out.println(c.contains("chenyong"));
        System.out.println(c.isEmpty());
        System.out.println(c.size());


        //迭代器:并发修改异常
//        System.out.println("迭代器");
//        Iterator<String> it = c.iterator();
//        while (it.hasNext()) {
//            String s = it.next();
//            c.add("chenyong");
//            System.out.println(s);
//        }
        //for循坏(向下转型)
        ArrayList<String> list = (ArrayList<String>) c;
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        //列表迭代器
        ListIterator<String> stringListIterator = list.listIterator();
        while(stringListIterator.hasNext()) {
            String next = stringListIterator.next();
            if("chenyong".equals(next)){
                stringListIterator.add("你是帅哥！");
            }
        }
        System.out.println(list);


    }

}
